package com.cbh.amadeus.common.handler;

import com.cbh.amadeus.common.enums.MessageType;
import com.cbh.amadeus.common.protocol.AmadeusMessageWrap;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author ChenBiHui
 * @date 2025/4/25
 */
@Slf4j
public class IdentifyHandler extends SimpleChannelInboundHandler<AmadeusMessageWrap> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, AmadeusMessageWrap msg) {
        MessageType type = MessageType.find(msg.getType());
        if (type == null) {
            log.warn("===== Illegal message type, Will refuse access =====");
            return;
        }
        if (type.getIdentify().apply(msg)) {
            return;
        }
        ctx.fireChannelRead(msg);
    }
}
